package org.karelun.gef.commands;

import org.karelun.gef.helper.ConstantMessages;
import org.karelun.gef.model.AttributeModel;
import org.karelun.gef.model.BaseClassModel;
import org.karelun.gef.model.ClassModel;
import org.karelun.gef.model.MethodModel;

public class CreateAttributeCommand extends AbstractCommand {

	private ClassModel classModel;

	private BaseClassModel attModel;

	// private Point location;

	public void setAttribute(BaseClassModel attributeModel) {
		this.attModel = attributeModel;
	}

	public void setClassModel(ClassModel classModel) {
		this.classModel = classModel;
	}

	// public void setLocation(Point location) {
	// this.location = location;
	// }

	public void execute() {
		// attributeModel.setLocation(location);
		if (attModel instanceof AttributeModel)
			classModel.addAttribute((AttributeModel) attModel);
		else if (attModel instanceof MethodModel)
			classModel.addMethod((MethodModel) attModel);

		attModel.setParent(classModel);
	}

	public String getLabel() {
		return ConstantMessages.CreateAttrCommand_Label_Text;
	}

	public void redo() {
		execute();
	}

	public void undo() {
		if(attModel instanceof AttributeModel)
		classModel.removeAttribute((AttributeModel)attModel);
		else if(attModel instanceof MethodModel)
			classModel.removeMethod((MethodModel)attModel);
	}
}